import dt from '@dt/dt'
import server from '@dt/server/dt'

const api = {
  list: server.api().post('/dt-building/data/filingList'),
  exportList: server.api().post('/dt-building/data/filingList/export').tag('downloadCenter'),
  isFiling: server.api().post('/dt-building/data/filing/confirmInfo'),
  filing: server.api().post('/dt-building/data/filing/confirm'),
  edit: server.api().post('/dt-building/data/filingList/update')
}

function list() {
  return api.list.fetch({ housesId: dt.buildInfo().housesId })
}

function exportList() {
  return api.exportList.fetch({ housesId: dt.buildInfo().housesId })
}

function isFiling() {
  return api.isFiling.fetch({ housesId: dt.buildInfo().housesId })
}

function filing(isFiling) {
  return api.filing.fetch({ housesId: dt.buildInfo().housesId, isFiling: isFiling ? 1 : 0 })
}

function edit(list) {
  return api.edit.fetch({
    contentRespList: list.map((itm) => ({
      extend: itm.extend,
      filingListId: itm.filingListId,
      manager: itm.manager,
      remark: itm.remark
    }))
  })
}

export default {
  list,
  exportList,
  isFiling,
  filing,
  edit
}
